//
//  MineHomeViewController.m
//  WeCommunity
//
//  Created by mac on 2017/6/14.
//  Copyright © 2017年 lzy. All rights reserved.
//

#import "MineHomeViewController.h"
#import "MineCotentListView.h"
#import "MineInfoViewController.h"
#import "MineCollectionViewController.h"
#import "MineHadSentInfoViewController.h"
#import "AdminReportViewController.h"
#import "HHSignInViewController.h"
#import "HHCoinViewController.h"
#import "HHRuleViewController.h"
#import "HHLikeRecordViewController.h"

@interface MineHomeViewController ()<MineCotentListDelegate>

@property (nonatomic,strong) MineCotentListView * contentListView;

@end

@implementation MineHomeViewController

-(void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

#pragma mark - get
-(MineCotentListView *)contentListView
{
    if(!_contentListView){
        _contentListView = [[MineCotentListView alloc] initWithFrame:CGRectMake(0, 0, KScreen_Width, KScreen_Height - KNaviheight - KTabBarHeight)];
        _contentListView.delegate = self;
    }
    _contentListView.contact = [UserInfoManger shared].contact;
    return _contentListView;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initWithUserInterface];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(userInfoMangerUpdateUserData:) name:USERLOGIN_CHANGE_NOTIKEY object:nil];
    
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    
}

-(void)initWithUserInterface
{

    self.view.backgroundColor = [UIColor colorWithHex:0xefeff4 alpha:1.0];
    
    [self.view addSubview:self.contentListView];
    [self.contentListView reloadWithData];
    
}

#pragma mark - 用户数据更新
-(void)userInfoMangerUpdateUserData:(NSNotification *)noti
{

    [self.contentListView reloadWithData];
}

#pragma mark - contentListView delegate
-(void)mineCotentListViewSelectRowAtIndex:(NSInteger)index
{
    if (![self canProcessNext]) {
        return;
    }
    
    switch (index) {
        case 0:
        {
            MineInfoViewController * infoVC = [[MineInfoViewController alloc] init];
            [self.navigationController pushViewController:infoVC animated:YES];
        }
            break;
        case 1: //签到
        {
            
            if(IS_CHINESE){
                HHSignInViewController *vc = [[HHSignInViewController alloc]initWithNibName:@"HHSignInViewController" bundle:nil];
                [self.navigationController pushViewController:vc animated:YES];
            }else{
                [self sureAlertWithTitle:@"Warm Prompt" andMesg:@"Function not yet open, please pay attention to our update"];
            }
            
        }
            break;
        case 2: //积分
        {
            HHCoinViewController *vc = [[HHCoinViewController alloc]initWithNibName:@"HHCoinViewController" bundle:nil];
            [self presentViewController:vc animated:true completion:nil];

        }
            break;
        
        case 3://我的发布
        {
            MineHadSentInfoViewController * sentVC = [[MineHadSentInfoViewController alloc] init];
            [self.navigationController pushViewController:sentVC animated:YES];
        }
            break;
            
        case 4: //点赞记录
        {
            HHLikeRecordViewController *vc = [[HHLikeRecordViewController alloc]init];
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
    
          
        case 5: //规则
        {
            HHRuleViewController *vc = [[HHRuleViewController alloc]initWithNibName:@"HHRuleViewController" bundle:nil];
            [self presentViewController:vc animated:true completion:nil];
        }
            break;
        case 6://退出登录
        {
            
            [self systemAlertWithTitle:KNSLocal(@"alertTitle") andMessage:HH_LOC_STR(@"Are you sure you want to log out?") actionTextOne:KNSLocal(@"alertCancel") actionTextTwo:KNSLocal(@"alertOK") actionOneBlock:^{
                
            } actionTwoBlock:^{
                [[UserInfoManger shared]logOutLogic];
            }];
            
        }
            break;
        case 7: //管理员权限
        {
            AdminReportViewController * adminVC = [[AdminReportViewController alloc] init];
            [self.navigationController pushViewController:adminVC animated:YES];
        }
            break;
          
        
          
            
        default:
            break;
    }
}


@end
